package pointer

func removeRepeatSliceOntarget(s []int, target int) []int {
	if len(s) == 0 {
		return s
	}
	i := 0
	// 1242552277
	// 145577
	for j := 0; j < len(s); j++ {
		if s[j] != target {
			s[i] = s[j]
			i++
		}
	}
	return s[:i]
}

// 12234466553863
// 123456
func removeRepeatSlice(s []int) []int {
	if len(s) == 0 {
		return s
	}
	i := 0
	sliceMap := make(map[int]bool)
	for j := 1; j < len(s); j++ {
		if _, ok := sliceMap[s[j]]; !ok {
			s[i] = s[j]
			i++
			sliceMap[s[j]] = true
		}
	}
	return s[:i]
}

// e.g. "a1b2c3" => "anumberbnumercnumber"
// replaceDigit
func replaceDigit(s string) string {
	if len(s) == 0 {
		return s
	}
	var result string
	for i := 0; i < len(s); i++ {
		if s[i] >= '0' && s[i] <= '9' {
			result += "number"
		} else {
			result += string(s[i])
		}
	}
	return result
}

// e.g. "the sky is blue" => "bule is sky the"
// reverseWords
func reverseWords(s string) string {
	if len(s) == 0 {
		return s
	}
	// "the sky is blue"
	// "eulb si yks eht"
	// "blue is sky the"
	i := len(s) - 1
	var result string
	for i >= 0 {
		if s[i] == ' ' {
			i--
			continue
		}
		j := i
		for j >= 0 && s[j] != ' ' {
			j--
		}
		result += s[j+1:i+1] + " "
		i = j
	}
	return result[:len(result)-1]
}
